import {
  getData,
  getCacheData
} from './request';

//通过外界传入store来修改
//Request URL:http://localhost:8080/api/jztk/query
//Request Method: POST
export default async (store) => {

  const {
    subjectId,
    modelType
  } = store.state;

  //获取后端数据
  // const data = await getData({
  //   subjectId: store.subjectId,
  //   modelType: store.modelType
  // });

  //获取缓存数据
  const data = await getCacheData({
    subjectId,
    modelType
  });

  //success: error_code: 0
  if (data.error_code !== 0) {
    console.log('errorCode has been modified in state!');
    store.commit('setErrorCode', data.error_code);
    return;
  }

  // console.log(data);
  //{reason: 'ok', result: Array(100), error_code: 0}

  //截取前5条答案存入state.data里
  const questionData = data.result.slice(0, 5);
  store.commit('setData', questionData);

  // return data;
}